package org.dreamwork.tools.code.analyzer.core.service;

import org.dreamwork.tools.code.analyzer.core.data.SystemConfig;
import org.dreamwork.util.StringUtil;

public interface ISystemConfigService extends IBaseService {
    @SuppressWarnings ("unchecked")
    default <T> T get (String key) {
        SystemConfig conf = getByPrimary (SystemConfig.class, key);
        if (conf != null) {
            String value = conf.getValue ();
            if (!StringUtil.isEmpty (value)) {
                switch (conf.getType ()) {
                    case "string":
                        return (T) value;
                    case "integer":
                    case "int":
                        return (T) Integer.valueOf (value.trim ());
                    case "boolean":
                        return (T) Boolean.valueOf (value.trim ());
                    case "float":
                        return (T) Float.valueOf (value.trim ());
                }
            }
        }
        return null;
    }
}